//
//  TTHomeCellModel.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/27.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTHomeCellModel.h"
#import "TTHomeViewOTO.h"
@implementation TTHomeCellModel


-(instancetype)initWithModel:(TTHomeModel*)model{
    
    if (self = [super init]) {
      
        self.cellModel = model;
    }
    
    return self;
}

-(void)setCellModel:(TTHomeModel *)cellModel{
    
    _cellModel = cellModel;
    
    self.verified_type = [self getVerified_typeWith:cellModel.user.verified_type];
    
    self.mbrank = [self getMbrankWith:cellModel.user.mbrank];
    
    self.souce = [self getSouceWith:cellModel.source];
}

/// 认证类型 -1：没有认证，1，认证用户，2,3,5: 企业认证，220: 达人
-(UIImage*)getVerified_typeWith:(NSInteger)type{
    
    switch (type) {
            
        case 0:
            return [UIImage imageNamed:@"avatar_vip"];
            break;
        case 2:
        case 3:
        case 5:
            return [UIImage imageNamed:@"avatar_grassroot"];
            break;
        case 220:
            return [UIImage imageNamed:@"avatar_enterprise_vip"];
            break;
        default:
            return [UIImage imageNamed:@"avatar_vgirl"];
            break;
    }
}

/// 会员等级 1-6
//@property (nonatomic,strong) UIImage * mbrank;
//

-(UIImage *)getMbrankWith:(NSInteger)mbrank{
    
    return [UIImage imageNamed:[NSString stringWithFormat:@"common_icon_membership_level%ld",mbrank]];
}


//2016-07-28 00:22:54.793 TTWeibo[2564:31266] <a href="http://app.weibo.com/t/feed/4swE93" rel="nofollow">三星android智能手机</a>

-(NSMutableAttributedString *)getSouceWith:(NSString*)souce{
    
    if (souce.length >0) {
        
        NSRange range = [souce rangeOfString:@"\">"];
        NSRange range2 = [souce rangeOfString:@"</"];
        
        NSString * souceString = [souce substringWithRange:NSMakeRange(range.location + range.length, range2.location - range.location - range.length)];
        
        return [self getAttributedString:souceString];
        
    }else{
        
        return [self getAttributedString:@"大强微博"];
    }

}

-(NSMutableAttributedString*)getAttributedString:(NSString *)souce{
    
    NSString * souceString = [NSString stringWithFormat:@"来自 %@",souce];
    
    NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:souceString];
    
    NSRange range = [souceString rangeOfString:@"来自"];
    
    [string addAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} range:range];
     
     return string;
}

@end
